// StatusWindow.h : Declaration of the CStatusWindow

#pragma once

#include "resource.h"       // main symbols
#include <atlhost.h>

//#include <rapi.h> 

//#define MSG(X) ::MessageBox(0,X,_T("Error"),MB_OK); \
//	OutputDebugString(X); \
//	OutputDebugString(_T("\n"))

#define MSG(X)\
	OutputDebugString(X); \
	OutputDebugString(_T("\n"))

//#define MSG(X) 

// CStatusWindow

class CStatusWindow : 
	public CAxDialogImpl<CStatusWindow>
	//public CAxWindowT<CStatusWindow>
{
public:

	CStatusWindow::CStatusWindow(unsigned int uNumFiles);
	
	//CStatusWindow(unsigned int uNumFiles,TCHAR ** szListOfFiles);

	void AddFileToQueue(TCHAR * lpszFile,unsigned int pos);
	
	~CStatusWindow();	

	enum { IDD = IDD_STATUSWINDOW };

	TCHAR **  m_szFile;
	volatile UINT m_uNumFiles;
	//TCHAR  m_szTargets[MAX_PATH][5];
	//int currCommand;

	TCHAR m_szTarget[MAX_PATH];
	
	CRITICAL_SECTION cs;	
	volatile bool finishThread;
	bool m_cleanEnd;
	HANDLE threadHandle;	

	
	HRESULT hrapi;	
	volatile bool m_fIsWaitingConnection;

BEGIN_MSG_MAP(CStatusWindow)
	MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog)
	COMMAND_HANDLER(IDOK, BN_CLICKED, OnClickedOK)
	COMMAND_HANDLER(IDCANCEL, BN_CLICKED, OnClickedCancel)
	MESSAGE_HANDLER(WM_CLOSE, OnClose)
	CHAIN_MSG_MAP(CAxDialogImpl<CStatusWindow>)
END_MSG_MAP()

	LRESULT OnClose(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/);
	
	LRESULT OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
	
	LRESULT OnClickedOK(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled);	

	LRESULT OnClickedCancel(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled);

	void FreeNonWindowRelatedBlocks();


	bool CopyFileToDevice(TCHAR * sourceFullPath, TCHAR * destinyFolder);
	void UpdateTotalProgressBar(DWORD moreBytesWritten);
	void WorkOnFilesRecursively (TCHAR * basicDir,UINT64 *accumulator,bool bCopyFiles);
	
	HWND hwndProgressBar;
	HWND hwndTotalProgressBar;

	UINT64 TotalBytesCopied;
	UINT64 TotalFileSize;

	TCHAR basicPathOnDesktop[MAX_PATH];

private:

	
};
